<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>北京航天公司固定资产管理系统</title>
</head>
<body>
<form class="layui-form" id="form">
    <div class="layui-form-item">
      <label class="layui-form-label">转移前信息</label>
      <div class="layui-input-inline">
        <select name="before_dep" id="before_dep" lay-filter="mySelect">
          <option value="-1">请选择原所属组织</option>
        </select>
      </div>
        <div class="layui-input-inline">
          <select name="before_org" id="before_org" lay-filter="mySelectOrgProperty">
            <option value="-1">请选择原所属部门/门店</option>
          </select>
        </div>
      <div class="layui-input-inline">
        <div class="layui-input-inline">
          <input type="text" name="before_person"  placeholder="原责任人" class="layui-input">
        </div>
      </div>
    </div>



    <div class="layui-form-item">
      <div class="layui-form-item">
        <label class="layui-form-label">转移后信息</label>
        <div class="layui-input-inline">
          <select name="after_dep" id="after_dep" lay-filter="after_mySelect">
            <option value="-1">请选择所属组织</option>
          </select>
        </div>
        <div class="layui-input-inline">
          <select name="after_org" id="after_org">
            <option value="-1">请选择所属部门/门店</option>
          </select>
        </div>
        <div class="layui-input-inline">
          <div class="layui-input-inline">
            <input type="text" name="after_person"  placeholder="责任人"  class="layui-input">
          </div>
        </div>
      </div>
      <div class="layui-form-item">
        <div class="layui-inline">
          <label class="layui-form-label">资产转移类型</label>
          <div class="layui-input-inline">
            <select name="transfer_type" id="transfer_type">
              <option value="" selected="">选择类型</option>
            </select>
          </div>
        </div>
        <div class="layui-inline">
          <label class="layui-form-label"> 资产转移日期</label>
          <div class="layui-input-inline">
            <input type="text" name="create_time" class="layui-input" id="create_time" placeholder="yyyy-MM-dd HH:mm:ss">
          </div>
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">需要转移资产</label>
        <div class="layui-input-block" id="propertyDiv">

        </div>
      </div>
      <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
          <textarea name="remarks" id="remarks" placeholder="请输入......" class="layui-textarea"></textarea>
        </div>
      </div>
  </div>
    <div class="layui-input-block">
      <button type="button" onclick="addTransfer()" class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
</form>
</body>
</html>
<script type="text/javascript"  src="/js/jquery-1.8.2.js"></script>
<script type="text/javascript"  src="/layui/layui.all.js" ></script>
<link rel="stylesheet" href="/layui/css/layui.css">
<script>
  var form = layui.form;
  var laydate = layui.laydate;
  $(function () {
    form.render();
    //日期
    laydate.render({
      elem: '#create_time',
      type:'datetime',
    });
    //初始化获取转移前部门信息
    initGetParent();
    //初始化获取转移后部门信息
    initGetParentAfter();
    //初始化获取所有资产转移类型
    initGetTransferType();
  });

  //监听提交
  form.on('select(mySelectOrgProperty)', function(data){
    $("#propertyDiv").empty();
    $.post("/transfer/selectPropertyByDid?did="+$("select[name='before_org']").val(),function (res) {
        for (var i in res) {
          $("#propertyDiv").append("<input type='checkbox' name='property_id' id='property_id'  value='"+res[i].property_id+"' title='"+res[i].property_name+"'>");
        }
      form.render();
    },"json");
  });


  function initGetTransferType() {
    $.post("/transfer/selectTransferType",function (res) {
      for (var i in res) {
        $("select[name='transfer_type']").append("<option value='"+res[i].id+"'>"+res[i].name+"</option>")
      }
      form.render();
    },"json");
  }

  function initGetParent() {
    $.post("/transfer/selectByParentId?did=0",function (res) {
      for (var i in res) {
        $("select[name='before_dep']").append("<option value='"+res[i].did+"'>"+res[i].dname+"</option>");
      }
      form.render();
    },"json");
  }

  //监听提交
  form.on('select(mySelect)', function(data){
    // $("select[name='before_org']").empty();
    $.post("/transfer/selectByParentId?did="+$("select[name='before_dep']").val(),function (res) {
      for (var i in res) {
        $("select[name='before_org']").append("<option value='"+res[i].did+"'>"+res[i].dname+"</option>");
      }
      form.render();
    },"json");
  });

  function initGetParentAfter() {
    $.post("/transfer/selectByParentId?did=0",function (res) {
      for (var i in res) {
        $("select[name='after_dep']").append("<option value='"+res[i].did+"'>"+res[i].dname+"</option>");
      }
      form.render();
    },"json");
  }

  //监听提交
  form.on('select(after_mySelect)', function(data){
    // $("select[name='after_org']").empty();
    $.post("/transfer/selectByParentId?did="+$("select[name='after_dep']").val(),function (res) {
      for (var i in res) {
        $("select[name='after_org']").append("<option value='"+res[i].did+"'>"+res[i].dname+"</option>");
      }
      form.render();
    },"json");
  });


  function addTransfer() {

    var depar_id = $("#before_org option:selected").val();

    var after_depar_id = $("#after_org option:selected").val();

    var before_organization = $("#before_dep option:selected").text();
    var before_department = $("#before_org option:selected").text();
    var before_person = $("input[name='before_person']").val();


    var after_organization = $("#after_dep option:selected").text();
    var after_department = $("#after_org option:selected").text();
    var after_person = $("input[name='after_person']").val();

    var transfer_type = $("#transfer_type option:selected").val();

    var create_time = $("#create_time").val();

    var checks = $(":checkbox:checked");
    var ids = new Array(checks.length);
    for (var i=0;i<ids.length ; i++){
        ids[i] = checks[i].value
    }

    var remarks = $("#remarks").val();


    $.post("/transfer/add?transfer_type="+transfer_type+"&property_id="+ids+"&create_time="+create_time+"&before_organization="+before_organization+"&before_department="+before_department+"&before_person="+before_person+"&after_organization="+after_organization+"&after_department="+after_department+"&after_person="+after_person+"&remarks="+remarks+"&depar_id="+depar_id+"&after_depar_id="+after_depar_id,function (data) {

        if(data >0){
          layer.alert("资产转移申请成功")
          setTimeout(function () {
            window.location.href = '/jump/goTransferIndex'
          },1000)
        }else {
          layer.alert("资产转移申请失败")
        }
    },"json");
  }

</script>